package com.itheima.myset;

import java.util.ArrayList;
import java.util.Comparator;
import java.util.TreeSet;

public class Demo2 {
    public static void main(String[] args) {
        TreeSet<Teacher> ts = new TreeSet<>(new Comparator<Teacher>() {
            @Override
            public int compare(Teacher o1, Teacher o2) {
                int res = o1.getAge() - o2.getAge();
                int res1 = res == 0 ? o1.getName().compareTo(o2.getName()):res;
                return res1;
            }
        });
        Teacher t1 = new Teacher("zhangsan", 20);
        Teacher t2 = new Teacher("lisi", 14);
        Teacher t3 = new Teacher("wangwu", 18);
        Teacher t4 = new Teacher("zhaoliu", 20);
        ts.add(t1);
        ts.add(t2);
        ts.add(t3);
        ts.add(t4);

    }
}

class Teacher {
    private String name;
    private int age;

    public Teacher() {
    }

    public Teacher(String name, int age) {
        this.name = name;
        this.age = age;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }
}